<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<x:parse xml="${param.xmlstr}" var="xmlData" />
<c:set var="title">经费预算表</c:set>
<c:if test="${not empty param.title }"><c:set var="title">${param.title }</c:set></c:if>

<!-- <div class="t_bar2">
	试制设备费预算明细表
</div> -->

<table  id="tblMainPsn" cellpadding="0" class="table01 t_css" width="100%" border="0" cellpadding="0" style="*border-bottom: #a1c0dc 1px solid;">
			<col width="5%" />
			<col width="5%" />
			<col width="10%" />
			<col width="7%" />
			<col width="13%" />
			<col width="17%" />
			<col width="15%" />
			<col width="15%" />
			<col width="13%" />
			<thead >
				<tr style="border:1px solid #B7D1E6">
					<th class="TblHead" align="center" >选择</th>
					<th class="TblHead" align="center" >序号</th>
					<th class="TblHead" align="center" >姓名</th>
					<th class="TblHead" align="center" >性别</th>
					<th class="TblHead" align="center" >出生年月</th>
					<th class="TblHead" align="center" >职称</th>
					<th class="TblHead" align="center" >学历</th> 
					<th class="TblHead" align="center" >工作单位</th>
					<th class="TblHead" align="center" >对成果创造性贡献</th> 
				</tr>
			</thead>
			<tbody id="tab">
			<input type="hidden" id="nowDate" value="${sercverSysDate1}" label="当前日期"/>
					<tr style="display:none"  align="center">
						<td align="center">
							<input type="radio" class="radiobutton" name="selmainpsn" onclick="setSubmitPsn()" >
						</td>
						<td align="center">
							<span name="zh_persons|zh_person[0]@submit_psn" >[index]</span> 
						</td>
						<td align="center">
						<input type="text" name="zh_persons|zh_person[0]|basic_info|zh_name" label="姓名"  maxlength="50" style="width:80%" class="required input_text"/>
						</td>
						<td align="center">						
							<cpt:select id="gender[index]"  name="gender" key="gender" style="width:40px;" onChange="initControlValue(this.id)"></cpt:select>
							<input type="hidden" name="zh_persons|zh_person[0]|basic_info|gender_value" value="" label="性别"  class="required"/>
							<input type="hidden" name="zh_persons|zh_person[0]|basic_info|gender_name" value="" label="性别"  />
						</td>
						<td align="center">
							<!-- <input  id="experience_end_date_[0]" name="experiences|experience[0]|end_date" label="结束日期" value="" class=" required input_text date" style="width:70%;"  /> -->
							<input id="birth_date_[0]" name="zh_persons|zh_person[0]|basic_info|birth_date"  class=" required date  dateCompare:nowDate" label="出生年月"  size="10%;"/>
						</td>
						<td align="center">						
			          	<cpt:tree key="prof_title" cacheable="false" className="" readonly="true" value="" label="职称"  width="100px"
			          		id="prof_title_[index]" name="prof_title" showPattern="all" shieldPattern="0" onClick="initTreeValueExt"/>
				        	<input type="hidden" name="zh_persons|zh_person[0]|basic_info|prof_title_value" class="required" label="职称" value=""/>
			           	<input type="hidden" name="zh_persons|zh_person[0]|basic_info|prof_title_name" value=""/>
						</td>
						<td align="center">						
							<cpt:select id="educate[index]"  name="educate" key="educate" onChange="initControlValue(this.id)"></cpt:select>
							<input type="hidden" name="zh_persons|zh_person[0]|basic_info|educate_value" value="" label="学历"  class="required"/>
							<input type="hidden" name="zh_persons|zh_person[0]|basic_info|educate_name" value="" label="学历"  />
						</td>
						<td align="center">
							<input type="text" name="zh_persons|zh_person[0]|basic_info|org_name" label="工作单位"  maxlength="50" style="width:80%" class="required input_text"/>
						</td>
						<td align="center">
							<input type="text" name="zh_persons|zh_person[0]|basic_info|result" label="对成果创造性贡献"  maxlength="50" style="width:80%" class="required input_text"/>
						</td>
					</tr>
					 <c:set value="0" var="index" scope="page"/>
					<x:forEach select="$xmlData/data/zh_persons/zh_person" var="zh_person">
					
					<c:choose>
						<c:when test="${index<10}" ><c:set value="0" var="flag" scope="page"/></c:when>
						<c:otherwise><c:set value="" var="flag" scope="page"/></c:otherwise>
					</c:choose>
					<c:choose>
					<c:when test="${index eq 0}">
						<tr   align="center">
							<td>
								<input type="radio" class="radiobutton" name="selmainpsn" onclick="setSubmitPsn()" >
							</td>
							<td align="center">
								<span   name="zh_persons/zh_person[${flag}${index}]@submit_psn" >${index+1}</span> 
							</td>
							<td align="center">
							   <span name="zh_persons/zh_person[${flag}${index}]/basic_info/zh_name"><x:out select="$zh_person/basic_info/zh_name" /></span>
							</td>
							<td align="center">						
						    	<c:set var="gender"><x:out select="$zh_person/basic_info/gender_value" /></c:set>
						    	<span name="zh_persons/zh_person[${flag}${index}]/basic_info/gender_name">
						    		<c:choose>
								    	<c:when test="${gender eq 'M' }"><c:set var="gender">1</c:set>男</c:when>
								    	<c:when test="${gender eq 'F' }"><c:set var="gender">2</c:set>女</c:when>
								    	<c:when test="${gender eq '1' }">男</c:when>
								    	<c:when test="${gender eq '2' }">女</c:when>
							    	</c:choose>
						    	</span>
								<input type="hidden" name="zh_persons/zh_person[${flag}${index}]/basic_info/gender_value" value="${gender}" label="性别"  class="required"/>
							</td>
							<td align="center">
								<c:set var = "birth_date"><x:out select="$zh_person/basic_info/birth_date"/> </c:set>
								<span name="zh_persons/zh_person[${flag}${index}]/basic_info/birth_date">
									<c:if test="${empty birth_date}"><x:out select="$zh_person/basic_info/birthday"/></c:if>
									<c:if test="${not empty birth_date}">${birth_date}</c:if>
								</span>
							</td>
							<td align="center">
								<span name="zh_persons/zh_person[${flag}${index}]/basic_info/prof_title_name"><x:out select="$zh_person/basic_info/prof_title_name" /></span>
					        	<input type="hidden" name="zh_persons/zh_person[${flag}${index}]/basic_info/prof_title_value" class="required" label="职称" value="<x:out select="$zh_person/basic_info/prof_title_value" />"/>
						 	</td>
							<td align="center">		
								<span  name="zh_persons/zh_person[${flag}${index}]/basic_info/educate_name"><x:out select="$zh_person/basic_info/educate_name" /></span>				
								<input type="hidden" name="zh_persons/zh_person[${flag}${index}]/basic_info/educate_value" value="<x:out select="$zh_person/basic_info/educate_value" />" label="学历"  class="required"/>
							</td>
							<td align="left">
							   <span name="zh_persons/zh_person[${flag}${index}]/basic_info/org_name" ><x:out select="$zh_person/basic_info/org_name" /></span>
							</td>
							<td align="center">
							   <input type="text" name="zh_persons/zh_person[${flag}${index}]/basic_info/result"   label="对成果创造性贡献"   style="width:80%" maxlength="50"  class="required input_text" value="<x:out select="$zh_person/basic_info/result" />"/>
							</td>
						</tr>
					</c:when>
					<c:when test="${index ne 0}">
						<tr   align="center">
							<td>
								<input type="radio" class="radiobutton" name="selmainpsn" onclick="setSubmitPsn()" >
							</td>
							<td align="center">
								<span   name="zh_persons/zh_person[${flag}${index}]@submit_psn" >${index+1}</span> 
							</td>
							<td align="center">
							   <input type="text" name="zh_persons/zh_person[${flag}${index}]/basic_info/zh_name"   label="姓名"   style="width:80%" maxlength="50"  class="required input_text" value="<x:out select="$zh_person/basic_info/zh_name" />"/>
							</td>
							<td align="center">						
						    	<c:set var="gender"><x:out select="$zh_person/basic_info/gender_value" /></c:set>
						    	<c:if test="${gender eq 'M' }"><c:set var="gender">1</c:set></c:if>
						    	<c:if test="${gender eq 'F' }"><c:set var="gender">2</c:set></c:if>
								<cpt:select id="gender${index}" name="gender" value="${gender }" key="gender" style="width:40px;" onChange="initControlValue(this.id)" ></cpt:select>
								<input type="hidden" name="zh_persons/zh_person[${flag}${index}]/basic_info/gender_value" value="<x:out select="$zh_person/basic_info/gender_value" />" label="性别"  class="required"/>
								<input type="hidden" name="zh_persons/zh_person[${flag}${index}]/basic_info/gender_name" label="性别" value="<x:out select="$zh_person/basic_info/gender_name" />" />
							</td>
							<td align="center">
								<c:set var="birthday" scope="page"><x:out select="$zh_person/basic_info/birth_date"/></c:set>
								<cpt:date id="birth_date" name="zh_persons/zh_person[${flag}${index}]/basic_info/birth_date" value="${birthday}" className=" required date  dateCompare:nowDate" label="出生年月"  size="10%;" ></cpt:date>
						</td>
							<td align="center">
							<c:set var="prof_title">{'id':'<x:out select="$zh_person/basic_info/prof_title_value" />','name':'<x:out select="$zh_person/basic_info/prof_title_name" />'}</c:set>
				          	<cpt:tree key="prof_title" cacheable="false" className="" readonly="true" value="${prof_title}" label="职称"  width="100px"
				          		id="prof_title_${flag}${index}" name="prof_title" showPattern="all" shieldPattern="0" onClick="initTreeValueExt"/>
					        	<input type="hidden" name="zh_persons/zh_person[${flag}${index}]/basic_info/prof_title_value" class="required" label="职称" value="<x:out select="$zh_person/basic_info/prof_title_value" />"/>
				           	<input type="hidden" name="zh_persons/zh_person[${flag}${index}]/basic_info/prof_title_name" value="<x:out select="$zh_person/basic_info/prof_title_name" />"/>
						 	</td>
							<td align="center">						
							   <c:set var="educate_value"><x:out select="$zh_person/basic_info/educate_value" /></c:set>
								<cpt:select id="educate${index}" name="educate" value="${educate_value }" key="educate" onChange="initControlValue(this.id)" ></cpt:select>
								<input type="hidden" name="zh_persons/zh_person[${flag}${index}]/basic_info/educate_value" value="<x:out select="$zh_person/basic_info/educate_value" />" label="学历"  class="required"/>
								<input type="hidden" name="zh_persons/zh_person[${flag}${index}]/basic_info/educate_name" label="学历" value="<x:out select="$zh_person/basic_info/educate_name" />" />
							</td>
							<td align="center">
							   <input type="text" name="zh_persons/zh_person[${flag}${index}]/basic_info/org_name"   label="工作单位"   style="width:80%" maxlength="50"  class="required input_text" value="<x:out select="$zh_person/basic_info/org_name" />"/>
							</td>
							<td align="center">
							   <input type="text" name="zh_persons/zh_person[${flag}${index}]/basic_info/result"   label="对成果创造性贡献"   style="width:80%" maxlength="50"  class="required input_text" value="<x:out select="$zh_person/basic_info/result" />"/>
							</td>
						</tr>
					</c:when>
					</c:choose>
					<c:set value="${index+1}" var="index" scope="page"/>
					</x:forEach>
				</tbody>
				<script type="text/javascript">
						showAllDateTag("tblMainPsn");
				</script> 
				 </table>
				  
					<table width="98%" align="center">
					<tr><td>
					<input class="button" id="cmdAddbefore2" name="cmdAddbefore2" type=button value="添加" onclick="if(checkTabLimit('tblMainPsn',50,'主要研制人员名单最多只能填写50条')){addNewRow('tblMainPsn');showDateTag('tblMainPsn');}try{top.resizeFrame();}catch(e){};">
					<input class="button" id="cmdMovePrev2" name="cmdMovePrev2" type=button value="上移" onclick="movePrev('tblMainPsn','selmainpsn')">
					<input class="button" id="cmdMoveNext2" name="cmdMoveNext2" type=button value="下移" onclick="moveNext('tblMainPsn','selmainpsn')">
					<input class="button" id="cmddel2" name="cmddel2" type=button  value="删除" onclick="deleteSelectedRow('tblMainPsn','主要研制人员名单')">
					</td></tr>
	</table>

	<script type="text/javascript">
	/**
	* 选择树设置隐藏域值 public.js中原函数不适用，针对treeId中包含下标的情况
	*/
	function initTreeValueExt(treeId, treeNode) {

		var inputId = treeId.substring(0, treeId.lastIndexOf('_'));
		if (!(treeNode && (treeNode.level > 0 || !treeNode.isParent))) {
			scmWarn($("#" + treeId).attr("label")
					+ messageTip.researchAreaInvalidDisciplineCode);
			if (treeNode.level == 0) {
				$("#" + treeId).val("");
				$("#" + treeId).parents("td").find("[name$='" + inputId + "_code'],[id$='" + inputId+ "_code']").val("");
				$("#" + treeId).parents("td").find("[name$='" + inputId + "_value'],[id$='" + inputId+ "_value']").val("");
				$("#" + treeId).parents("td").find("[name$='" + inputId + "_name'],[id$='" + inputId+ "_name']").val("");
			}
			return false;
			}
			var str = treeNode.name;
			var obj = treeNode.parentNode;
			while (obj != null) {
				//str = obj.name + "-" + str;
				obj = obj.parentNode;
			}
			$("#" + treeId).parents("td").find("[name$='" + inputId + "_code'],[id$='" + inputId+ "_code']").val(treeNode.id);
			$("#" + treeId).parents("td").find("[name$='" + inputId + "_value'],[id$='" + inputId+ "_value']").val(treeNode.id);
			$("#" + treeId).parents("td").find("[name$='" + inputId + "_name'],[id$='" + inputId+ "_name']").val(str);
		}
	
	/**
	 * 重新计算行号
	 * @param tblId
	 */
	function refreshRowINdex(tblId){
		 //重新计算行号

		
		  $("#"+tblId+" tr").each(function(){
			  
			   var seq=$(this).get(0).rowIndex;//获得行数
			   if(seq>1){//如果有行  显示时display行不计入类，故只减1
				   
				   seq=seq-1;
				   var seq_no=$(this).find("[name$='submit_psn']");
				   if(seq_no.is("span"))
					   seq_no.html(seq);
				   else
					   seq_no.val(seq);
				   
				   seq=""+(seq-1);
				   if(seq.length==1)
					   seq="0"+seq;
				  //替换相应的name参数的seq
				  $(this).find("input,span,textarea,select").each(function(){
					   var name=$(this).attr("name");
					   if(name!=null&&name!=""){
						   name=name.replace(/\[\d*\]/g,"["+seq+"]");
						   $(this).attr("name",name);
					   }
					   var id=$(this).attr("id");
					   if(id!=null&&id!=""){
						   id=id.replace(/\[\d*\]/g,"["+seq+"]");
						   $(this).attr("id",id);
						   id=id.replace(/\d+/g,""+seq+"");
						   $(this).attr("id",id);
					   }
					   var className=$(this).attr("class");
					   var clickEvent = $(this).attr("onclick");
					   if(clickEvent != null && clickEvent !="" && className != "radiobutton"){
						   $(this).attr("onclick","show_prof_title_(this.id,{'locale':'zh_CN','key':'prof_title','cacheable':'false','sqlParamVal':''});");
					   } 
					   
					   
					   
					   
					   if(className!=null&&className!=""){
						   className=className.replace(/\[\d*\]/g,"["+seq+"]");
						   $(this).attr("class",className);
					   }
				   });
			   }
			 }
		  );

	}
	
	
	function setSubmitPsn() {
		if($("#tblMainPsn :radio:checked").length==0){
			scmWarn('请选择一行!');
			return false;
		}
		var tr = $("#tblMainPsn :radio:checked").parents("tr");
		if (tr.get(0).rowIndex - 1 == 1) {// 如果选择的是申报人
			$("#cmdMovePrev2").attr("disabled", "true").css("color", "#808080");
			$("#cmdMoveNext2").attr("disabled", "true").css("color", "#808080");
			// $("#zh_psnEdit").attr("disabled","true").css("color","#808080");
			$("#cmddel2").attr("disabled", "true").css("color", "#808080");

		} else if (tr.get(0).rowIndex - 1 == 2) {// 如果是申报书的下一行
			$("#cmdMovePrev2").attr("disabled", "true").css("color", "#808080");
			$("#cmdMoveNext2").removeAttr("disabled").css("color", "#FFFFFF");
			$("#cmddel2").removeAttr("disabled").css("color", "#FFFFFF");
		} else {
			$("#cmdMovePrev2").removeAttr("disabled").css("color", "#FFFFFF");
			$("#cmdMoveNext2").removeAttr("disabled").css("color", "#FFFFFF");
			// $("#zh_psnEdit").removeAttr("disabled").css("color","#003366");
			$("#cmddel2").removeAttr("disabled").css("color", "#FFFFFF");
		}
	}
	
	/**
	 * 下移行
	 * @param tblId
	 * @returns {Boolean}
	 */
	function moveNext(tblId,selName) {
		if (!selName)
			selName = "";
		if ($("#" + tblId + " :radio[name*='" + selName + "']:checked").length == 0) {
			scmWarn(irisNotes.nextWarn);
			return false;
		}
		if ($("#" + tblId + " tr").length <= 2) {
			return false;
		}
		var trChecked = $("#" + tblId + " :radio[name*='" + selName + "']:checked")
				.parents("tr").first();// 取得被选中的行
		var trNext = trChecked.next();
		var index = trChecked.get(0).rowIndex;// 获得行号
		if (index == $("#" + tblId + " tr").length - 1) {// 如果是第一行
			scmWarn(irisNotes.tabelMoveWarn2);
			return false;
		}
		//trChecked.remove();
		trNext.after(trChecked);
		trChecked.find(":radio[name*='" + selName + "']").attr("checked", "true");
		refreshRowINdex(tblId);
		setSubmitPsn();
	}
	
	 
	 /**
		 * 上移行
		 * @param tblId
		 * @returns {Boolean}
		 */
		function movePrev(tblId,selName) {

			if (!selName)
				selName = "";
			if ($("#" + tblId + " :radio[name*='" + selName + "']:checked").length == 0) {
				scmWarn(irisNotes.prevWarn);
				return false;
			}
			if ($("#" + tblId + " tr").length <= 2)
				return false;
			var trChecked = $("#" + tblId + " :radio[name*='" + selName + "']:checked")
					.parents("tr").first();// 取得被选中的行
			var trPrev = trChecked.prev();// 取得上一行
			var index = trChecked.get(0).rowIndex;// 获得行号
			if (index <= 2) {// 如果是第一行
				scmWarn(irisNotes.tabelMoveWarn1);
				return false;
			}
			//trChecked.remove();
			trPrev.before(trChecked);
			trChecked.find(":radio[name*='" + selName + "']").attr("checked", 'true');
			refreshRowINdex(tblId);
			setSubmitPsn();
		}
	</script>
	